<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>校园助手系统注册界面</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="https://www.jq22.com/jquery/bootstrap-4.2.1.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,700">
    <link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet">
	<script src="layui-admin/layui/layui.js"></script>
  </head>
  <body>
    <div class="page login-page">
      <div class="container d-flex align-items-center">
        <div class="form-holder has-shadow">
          <div class="row">
            <!-- Logo & Information Panel-->
            <div class="col-lg-6">
              <div class="info d-flex align-items-center">
                <div class="content">
                  <div class="logo">
                    <h1>欢迎注册</h1>
                  </div>
                  <p>校园助手系统</p>
                </div>
              </div>
            </div>
            <!-- Form Panel    -->
            <div class="col-lg-6 bg-white">
              <div class="form d-flex align-items-center">
                <div class="content">
                    <div class="form-group">
                      <input id="register-username" class="input-material" type="text" name="registerUsername" placeholder="请输入学号/工号" >
								      <div class="invalid-feedback">
								        	用户名必须在2~10位之间
								      </div>
                    </div>
                    <div class="form-group">
                      <input id="register-password" class="input-material" type="password" name="registerPassword" placeholder="请输入密码"   >
                    	<div class="invalid-feedback">
								        	密码必须在6~10位之间
								      </div>
                    </div>
                    <div class="form-group">
                      <input id="register-passwords" class="input-material" type="password" name="registerPasswords" placeholder="确认密码"   >
                    	<div class="invalid-feedback">
								        	两次密码必须相同 且在6~10位之间
								      </div>
                    </div>
                    <div class="form-group">
                      <button id="regbtn" type="button" onclick="doregister()" name="registerSubmit" class="btn btn-primary" >注册</button>
                    </div>
                  <small>已有账号?</small><a href="../login2/login.html" class="signup">&nbsp;登录</a>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- JavaScript files-->
    <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
    <script src="https://www.jq22.com/jquery/bootstrap-4.2.1.js"></script>
    <script>
    layui.use('layer', function () {
			layer = layui.layer;
			$ = layui.jquery;

			// 获取焦点
			$('#lregister-username').focus();

			// 直接回车登录
			$('input').keydown(function (e) {
				if (e.keyCode == 13) {
					dologin();
				}
			});
		});

		//登录
		function doregister() {
      var usrture =/^\d{10}$/
			//教师工号判断
			var usrtures =/^\d{4}$/
			var username = $.trim($('#register-username').val());
      var num=usrture.test(username);
			var nums=usrtures.test(username);
			var password = $('#register-password').val();
			var passwords = $('#register-passwords').val();
      localStorage.setItem("LoginName", username);
			if (username == '') {
				layer.alert('请输入学号/工号', { 'icon': 2 });
				return;
			}
			if (password == '') {
				layer.alert('密码不能为空', { 'icon': 2 });
				return;
			}
			if (password != passwords) {
				layer.alert('两次密码不相同重新输入', { 'icon': 2 });
				return;
			}
			if(num==true){
			$.ajax({
				url: "http://127.0.0.1:8000/doregister",
				type: "post",
				dataType: "JSON",
				data: { "username": username, "password": password,"passwords": passwords,"gid":2 },
				success: function (res) {
					if (res.code > 0) {
						layer.msg(res.msg);
					}
					if (res.code == 0) {
						layer.msg(res.msg);
						setTimeout(function () { window.location.href = 'userInfo/userInfo.html' }, 1000);
					}
				}
			})
    }
    if(nums==true){
			$.ajax({
				url: "http://127.0.0.1:8000/doregister",
				type: "post",
				dataType: "JSON",
				data: { "username": username, "password": password,"passwords": passwords,"gid":3 },
				success: function (res) {
					if (res.code > 0) {
						layer.msg(res.msg);
					}
					if (res.code == 0) {
						layer.msg(res.msg);
						setTimeout(function () { window.location.href = 'userInfo/userInfo.html' }, 1000);
					}
				}
			})
    }
		}
    </script>
  </body>
</html>